<template>
    <div>
        <Modal v-model="submit.isOpen" title="维修建议" @on-ok="submitForm">
            <Form
                    ref="formValidate"
                    :model="submit.adviceForm"
                    :rules="submit.ruleValidate"
                    :label-width="80"
            >
                <FormItem label="预计维修费用" prop="cost">
                    <InputNumber
                            :step="1.0"
                            :precision="2"
                            size="large"
                            :style="{ width: 200 + 'px' }"
                            :min="0"
                            v-model="submit.adviceForm.cost"
                    >
                    </InputNumber>
                </FormItem>
                <FormItem label="故障分析" prop="repairInfo">
                    <Input
                            v-model="submit.adviceForm.repairInfo"
                            type="textarea"
                            :rows="5"
                            placeholder="故障分析"
                    ></Input>
                </FormItem>
            </Form>
        </Modal>

    </div>
</template>

<script>
    import {postAdvice} from "@/api"

    export default {
        name: "advice",
        props: {
            value: {
                type: Boolean,
                default: false
            },
            orderId: {
                type: String,

            },
            id: {
                type: Number,
                default: null
            }
        },
        data() {
            return {
                submit: {
                    isOpen: false,
                    adviceForm: {
                        id: null,
                        cost: 0.0,
                        repairInfo: "",
                        orderId: ""
                    },
                    ruleValidate: {
                        cost: [
                            {required: true, type: "number", message: "预计维修费用不能为空", trigger: "blur"},
                        ],
                        repairInfo: [
                            {required: true, message: "故障分析不能为空", trigger: "blur"},
                        ]
                    }
                },
            }
        },
        methods: {
            submitForm() {
                postAdvice(this.submit.adviceForm).then(d => {
                    if (d && d.meta && d.meta.isSuccess) {
                        this.$Message.success("提交成功")
                        this.$emit("ok")
                    } else {
                        this.$Message.error("提交失败!" + d.meta.msg)
                    }
                })
            }
        },
        watch: {
            value(v) {
                this.submit.isOpen = v
            },
            "submit.isOpen"(v) {
                this.$emit("input", v)
            },
            id(v) {
                this.submit.adviceForm.id = v
            },
            orderId(v) {
                this.submit.adviceForm.orderId = v
            }
        }
    }
</script>

<style scoped>

</style>
